
<template >
  <div style="">
    <header class="mint-header" style="font-size: 18px;">
      <div class="mint-header-button is-left">
        <button class="mint-button mint-button--default mint-button--normal" style="font-size: 15px;" @click="option">
          <span class="mint-button-icon">
            <i class="mintui mintui-back" />
          </span>
          <label class="mint-button-text">返回</label>
        </button>
      </div>
      <h1 class="mint-header-title">发布任务</h1>
      <div class="mint-header-button is-right" />
    </header>

    <!-- 发布任务 -->
    <div style="padding:10px 0px;background:#fff">
      <mt-field v-model="renwu.taskname" label="任务名称:" placeholder="输入任务名称" />
      <mt-cell :to="{name:'choose_employee',query: {type:'1', detail: JSON.stringify(renwu)
        }}" title="责任人" is-link>
        <span v-if="renwu.chargername.length<1" style="color:#999999">请选择责任人</span>
        <span v-else style="color:#999999">{{ renwu.chargername }}</span>
        <img slot="icon" src="../static/ren.png" width="20" height="20">
      </mt-cell>
      <mt-cell :to="{name:'choose_employee',query: {type:'2', detail: JSON.stringify(renwu)}}" title="
        抄送人" is-link>
        <span v-if="renwu.noticername.length<1" style="color:#999999">请选择抄送人</span>
        <span v-else style="color:#999999">{{ renwu.noticername }}</span>
        <img slot="icon" src="../static/chaosongren.png" width="20" height="20">
      </mt-cell>
      <picker :picdata="level" class="rd_picker" style="margin-left:0px;" pictitle="请选择重要级别" @getpicval="getlevelval" />

      <picker2 :picdata="level" :values="''" :pictitle="'预计完成时间'" :gettime.sync="renwu.taskdate" />
    </div>
    <div style="text-align:center;margin:10px 0;">
      <textarea v-model="renwu.context" style="border: 0; outline: none;padding:10px;width:100%;height:120px;" placeholder="请输入任务详情" rows="4" />
      </div>
    <div class="btn_f">
      <mt-button
        type="default"
        style="width:72px;height:36px;font-size:14px;margin-right:15px"
        @click="goback">取消</mt-button>
      <mt-button
        type="primary"
        style="width:72px;height:36px;font-size:14px;"
        @click="submitrenwu">发布</mt-button>
    </div>
  </div>

</template>

<script>
import picker2 from '~/components/picker2.vue'
import picker from '~/components/picker.vue'
import uploadpic from '~/components/uploadpic.vue'
import chouseperson from '~/components/chouseperson.vue'
import chousebumen from '~/components/chousebumen.vue'
export default {
  components: {
    uploadpic,
    chouseperson,
    chousebumen,
    picker,
    picker2
  },
  data () {
    return {
      renwu: {
        taskname: '',
        tasklevel: '',
        taskdate: '',
        context: '',
        charger: [],
        chargername: '',
        noticer: [],
        noticername: ''
      },
      level: [

      ],

      ts: this.newStore(),
      chouseval: '',
      popupVisible22: false,

      personlist: {},
      chousname: [],
      grantime: '请选择时间',

      handler: function (e) {
        e.preventDefault()
      }
    }
  },
  computed: {},
  mounted () {
    if (this.$route.query.detail)
      this.renwu = JSON.parse(this.$route.query.detail)
    this.getcodeData();
    // this.getrenwu()
    // this.getlevel()
    // this.getendtimeval()
  },
  methods: {
    getcodeData () {
      const req = {
        handle: '67A5B6FEF17D97DECF116BDF95B95C0B167942DD3F1604F9',
        supid: '0507',
        codetype: '05'
      }
      this.spost(this.ts, '/mainservlet', req).then(ts => {
        this.olddataList = ts.d.data.operation1


        for (let index = 0; index < ts.d.data.operation1.length; index += 1) {
          const a = {}

          a.showname = ts.d.data.operation1[index].hash.code_name
          a.showid = ts.d.data.operation1[index].hash.code_id
          this.level.push(a)
        }
      })
    },

    getlevelval (val) {
      console.log('getlevel', val)
      this.renwu.tasklevel = val.showid
    },
    getendtimeval (val) {
      // this.endtimeid = val.showid
    },
    submitrenwu () {
      if (this.renwu.taskname == '' || this.renwu.taskname == undefined) {
        this.$messagebox('提示', '请输入任务名称')
        return
      }
      if (this.renwu.charger == '') {
        this.$messagebox('提示', '请选择责任人')
        return
      }
      if (this.renwu.context == '') {
        this.$messagebox('提示', '请输入任务详情')
        return
      }
      const req = {
        handle: '1FA998754EC78E7D4E95A8D2219E38CB1371440F534AD2F0',
        taskname: this.renwu.taskname,
        tasklevel: this.renwu.tasklevel,
        taskdate: this.renwu.taskdate,
        context: this.renwu.context,
        charger: this.renwu.charger,
        noticer: this.renwu.noticer
      }
      console.log(req)
      // return

      this.spost(this.ts, '/mainservlet', req).then(ts => {
        if (ts.d.sflag == 'success') {
          this.$messagebox('提示', '发布成功').then(action => {
            this.$router.push({
              name: 'task',
              qery: {
                name: '任务'
              }
            })
          })
        }
      })
    },
    closepicker (val) {
      if (val) {
        this.closeTouch()
      } else {
        this.openTouch()
      }
    },
    closeTouch () {
      document
        .getElementsByTagName('body')[0]
        .addEventListener('touchmove', this.handler, { passive: false }) //阻止默认事件
    },
    openTouch () {
      document
        .getElementsByTagName('body')[0]
        .removeEventListener('touchmove', this.handler, { passive: false }) //打开默认事件
    },
    goback () {
      this.$router.push({ name: 'task', query: { name: '任务' } })
    },

    option () {
      this.$router.push({
        name: 'task',
        query: {
          name: ''
        }
      })
    },

    //mint时间选择器开始
    addtime () {
      this.$refs.picker.open()
    },

    deletime (index) {
      console.log(index)
      this.timedata.splice(index, 1)
      console.log(this.timedata)
    },
    //时间赋值
    handleConfirm (data) {
      console.log(data)
      this.carData.examintime = this.formatDate(data)
    },
    //时间选择优化函数
    formatDate (date) {
      const y = date.getFullYear()
      let m = date.getMonth() + 1
      m = m < 10 ? '0' + m : m
      let d = date.getDate()
      d = d < 10 ? '0' + d : d
      return y + '-' + m + '-' + d
    },
    handleConfirm2 () {
      //this.chouseval = this.$refs.picker.getValues()[0]
      this.popupVisible22 = false
    },

  }
}
</script>

<style scoped>
html,
body,
#app {
  height: 100% !important;
  background: #f3f3f3 !important;
}
.mr_5 {
  margin-right: 5px;
}

.anniu {
  float: left;
  border-radius: 2px;
  border: 1px solid #f3f3f3;
  background-color: white;
  padding: 10px;
}

ul li {
  height: 25px;
  line-height: 25px;
}
.blue {
  background: rgb(40, 169, 227);
  color: white;
}
.border_b {
  border-bottom: 1px solid #f3f3f3;
  width: 94%;
  margin: 0 auto;
  padding: 10px;
}
a {
  text-decoration: none;
}
.blockDiv {
  margin-top: 100px;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  overflow: scroll;
}
.block {
  width: calc(calc(100% / 2) - 10px);
  margin: 5px;
  height: 80px;
  text-align: center;
  box-sizing: border-box;
}
.info-title {
  padding: 10px;
  color: #ccc;
  font-size: 16px;
}
.bg-con {
  background: #fff;
  width: 95%;
  margin: 0 auto 5px;
}
.img_id img {
  width: 100%;
  margin: 10px 5px;
  text-align: center;
  box-sizing: border-box;
}
.mint-cell-wrapper {
  font-size: 14px;
}
.xuli_div {
  background: #fff;
  padding: 5px;
  font-size: 15px;
  width: 95%;
  margin: 0 auto;
}
.xuli_span {
  border-left: 3px solid #ccc;
  display: inline-block;
  padding-left: 5px;
}
.mint-field-core {
  text-align: right !important;
}
.mt_10 {
  margin-top: 10px;
}
.btn_f {
  margin: 10px;
  text-align: center;
}
</style>
